package level.model;

import java.util.HashMap;
import java.util.Map;

public class Component implements Addable
{
	public Component()
	{
		attributes = new HashMap<String, Attribute>();
	}

	public String getComponentName()
	{
		return componentName;
	}

	public void setComponentName(String componentName)
	{
		this.componentName = componentName;
	}

	public void addAttribute(Attribute a)
	{
		attributes.put(a.getName(), a);
	}

	public Map<String, Attribute> getAttributes()
	{
		return attributes;
	}
	
	public Attribute getAttribute(String search)
	{
		return attributes.get(search);
	}

	@Override
	public boolean equals(Addable addable)
	{
		Component comp = (Component) addable;
		if (componentName != comp.getComponentName())
			return false;
		else if (attributes.size() == comp.getAttributes().size())
		{
			for (String name : attributes.keySet())
			{
				if (!comp.getAttributes().containsKey(name)
						|| !(comp.getAttributes().get(name).equals(attributes
								.get(name))))
				{
					return false;
				}
			}
			return true;
		}
		return false;
	}

	@Override
	public Addable cloneAddable()
	{
		Component comp = new Component();
		comp.setComponentName(componentName);
		for (String name : attributes.keySet())
		{
			comp.addAttribute((Attribute) attributes.get(name).cloneAddable());
		}
		return comp;
	}

	private String componentName;
	private Map<String, Attribute> attributes;
}
